package com.kgc.util;

import com.kgc.constant.SysConstant;

/**
 * @Author：周申宇 <p>
 * @Date:2021/6/1 9:56
 * <p>
 * @Decription:  封装返回统一返回工具类
 */
public class ResultBuildUtil {

    /**
     * @Auther: 周申宇
     * <p>
     * @Date: 2021/6/1
     * <p>
     * @Description:  返回成功不带数据
     */
    public static ReturnResult success(){

        return success(null);
    }


    /**
     * @Auther: 周申宇
     * <p>
     * @Date: 2021/6/1
     * <p>
     * @Description:  返回成功带数据
     */
    public static <T> ReturnResult<T> success(T t){
        ReturnResult<T> result = new ReturnResult<>();
        result.setCode(SysConstant.SYS_RESP_SUCCESS_CODE);
        result.setMsg(SysConstant.SYS_RESP_SUCCESS_MSG);
        result.setData(t);
        return result;
    }

    /**
     * @Auther: 周申宇
     * <p>
     * @Date: 2021/6/1
     * <p>
     * @Description:  返回失败不带数据
     */
    public static <T> ReturnResult<T> fail(){
        ReturnResult<T> result = new ReturnResult<>();
        result.setCode(SysConstant.SYS_RESP_FAILD_CODE);
        result.setMsg(SysConstant.SYS_RESP_FAILD_CODE);
        result.setData(null);
        return result;
    }
    /**
     * @Auther: 周申宇
     * <p>
     * @Date: 2021/6/1
     * <p>
     * @Description:  返回失败不带数据，自定义状态说明
     */
    public static <T> ReturnResult<T> fail(String errrCode,String errorMsg){
        ReturnResult<T> result = new ReturnResult<>();
        result.setCode(errrCode);
        result.setMsg(errorMsg);
        result.setData(null);
        return result;
    }

}
